const formatCounts = (counts) => {
  if (counts) {
    return {
      spaces: counts.products_count,
      docs: counts.file_count,
      issues: counts.issue_count,
      members: counts.member_count,
    };
  }
  return {};
};

const formatSpaces = spaces => spaces.map(space => ({
  id: space.product_id,
  title: space.product_title,
  avatar: space.product_avatar,
  top: space.topping,
}));

export const formatCommunity = community => ({
  id: community.id,
  title: community.title,
  desc: community.description,
  avatar: community.avatar,

  owner: community.owner,

  counts: formatCounts(community.count_data),

  spaces: formatSpaces(community.products),

  created_at: community.created_at,
  updated_at: community.updated_at,
});

export const formatCommunities = communities => communities.map(item => formatCommunity(item));
